

function initialize() {

    var latlng = new google.maps.LatLng(-12.07, -77.09);
    var myOptions = {
    zoom: 15,
    center: latlng,
    mapTypeId: google.maps.MapTypeId.ROADMAP
    };


    map = new google.maps.Map(document.getElementById("map_canvas"),myOptions);

    //Almacen central (Cliente 1)
    marcarPunto(new google.maps.LatLng(-12.07677752156479, -77.0882404047088626), "KOMATSU MITSUI, Almacén Central ");
    //Cliente 2 -------------------------------------------------------------------------------------------------
    marcarPunto(new google.maps.LatLng(-12.068384280695359, -77.0934332275391), "Ferreiros S.A.C - Cliente 2");
    //Cliente 3 -------------------------------------------------------------------------------------------------
    marcarPunto(new google.maps.LatLng(-12.079253477381727, -77.10068592071536),"Embotelladora E.I.R.L - Cliente 3");
    //Cliente 4 -------------------------------------------------------------------------------------------------
    marcarPunto(new google.maps.LatLng(-12.064187561667781, -77.08618053436282),"Constructora Rio - Cliente 4");
    //Cliente 5 -------------------------------------------------------------------------------------------------
    marcarPunto(new google.maps.LatLng(-12.061123915290217, -77.09974178314212), "Aluminios Santa - Cliente 5");
    //Cliente 6 -------------------------------------------------------------------------------------------------
    marcarPunto(new google.maps.LatLng(-12.048717806856576, -77.10002189422607), "Fabricantes - Cliente 6");
    //Cliente 7 -------------------------------------------------------------------------------------------------
    marcarPunto(new google.maps.LatLng(-12.072547590253286, -77.06911259765627), "Nissa - Cliente 7");

//------------------------------------------------------------------------------------------------------------------------


    //Cliente 1,2
    console.log("1-2");
    calcularDistanciaEntre(new google.maps.LatLng(-12.07677752156479, -77.0882404047088626), new google.maps.LatLng
    (-12.068384280695359, -77.0934332275391));

    //*************************************************************************************************************************


    // cliente 1,3
    console.log("1-3");
    calcularDistanciaEntre(new google.maps.LatLng(-12.07677752156479, -77.0882404047088626), new
    google.maps.LatLng(-12.079253477381727, -77.10068592071536));


    //cliente 2,3
    console.log("2-3");
    calcularDistanciaEntre(new google.maps.LatLng(-12.068384280695359, -77.0934332275391), new google.maps.LatLng
    (-12.079253477381727, -77.10068592071536));

    //*************************************************************************************************************************


    //cliente 1,4
    console.log("1-4");
    calcularDistanciaEntre(new google.maps.LatLng(-12.07677752156479, -77.0882404047088626), new
    google.maps.LatLng(-12.064187561667781, -77.08618053436282));

    //cliente 2,4
    console.log("2-4");
    calcularDistanciaEntre(new google.maps.LatLng(-12.068384280695359, -77.0934332275391), new
    google.maps.LatLng(-12.064187561667781, -77.08618053436282));

    //cliente 3,4
    console.log("3-4");
    calcularDistanciaEntre(new google.maps.LatLng(-12.079253477381727, -77.10068592071536), new
    google.maps.LatLng(-12.064187561667781, -77.08618053436282));

    //*************************************************************************************************************************


    //cliente 1,5
    console.log("1-5");
    calcularDistanciaEntre(new google.maps.LatLng(-12.07677752156479, -77.0882404047088626), new
    google.maps.LatLng(-12.061123915290217, -77.09974178314212));

    //cliente 2,5
    console.log("2-5");
    calcularDistanciaEntre(new google.maps.LatLng(-12.068384280695359, -77.0934332275391), new
    google.maps.LatLng(-12.061123915290217, -77.09974178314212));

    //cliente 3,5
    console.log("3-5");
    calcularDistanciaEntre(new google.maps.LatLng(-12.079253477381727, -77.10068592071536), new
    google.maps.LatLng(-12.061123915290217, -77.09974178314212));

    //cliente 4,5
    console.log("4-5");
    calcularDistanciaEntre(new google.maps.LatLng(-12.064187561667781, -77.08618053436282), new
    google.maps.LatLng(-12.061123915290217, -77.09974178314212));

    //*************************************************************************************************************************

    //cliente 1,6
    console.log("1-6");
    calcularDistanciaEntre(new google.maps.LatLng(-12.07677752156479, -77.0882404047088626), new
    google.maps.LatLng(-12.048717806856576, -77.10002189422607));

    //cliente 2,6
    console.log("2-6");
    calcularDistanciaEntre(new google.maps.LatLng(-12.068384280695359, -77.0934332275391), new
    google.maps.LatLng(-12.048717806856576, -77.10002189422607));

    //cliente 3,6
    console.log("3-6");
    calcularDistanciaEntre(new google.maps.LatLng(-12.079253477381727, -77.10068592071536), new
    google.maps.LatLng(-12.048717806856576, -77.10002189422607));

    //cliente 4,6
    console.log("4-6");
    calcularDistanciaEntre(new google.maps.LatLng(-12.064187561667781, -77.08618053436282), new
    google.maps.LatLng(-12.048717806856576, -77.10002189422607));

    //cliente 5,6
    console.log("5-6");
    calcularDistanciaEntre(new google.maps.LatLng(-12.061123915290217, -77.09974178314212), new
    google.maps.LatLng(-12.048717806856576, -77.10002189422607));

    //*************************************************************************************************************************


    //cliente 1,7
    console.log("1-7");
    calcularDistanciaEntre(new google.maps.LatLng(-12.07677752156479, -77.0882404047088626), new
    google.maps.LatLng(-12.072547590253286, -77.06911259765627));

    //cliente 2,7
    console.log("2-7");
    calcularDistanciaEntre(new google.maps.LatLng(-12.068384280695359, -77.0934332275391), new
    google.maps.LatLng(-12.072547590253286, -77.06911259765627));

    //cliente 3,7
    console.log("3-7");
    calcularDistanciaEntre(new google.maps.LatLng(-12.079253477381727, -77.10068592071536), new
    google.maps.LatLng(-12.072547590253286, -77.06911259765627));

    //cliente 4,7
    console.log("4-7");
    calcularDistanciaEntre(new google.maps.LatLng(-12.064187561667781, -77.08618053436282), new
    google.maps.LatLng(-12.072547590253286, -77.06911259765627));

    //cliente 5,7
    console.log("5-7");
    calcularDistanciaEntre(new google.maps.LatLng(-12.061123915290217, -77.09974178314212), new
    google.maps.LatLng(-12.072547590253286, -77.06911259765627));

    //cliente 6,7
    console.log("6-7");
    calcularDistanciaEntre(new google.maps.LatLng(-12.048717806856576, -77.10002189422607), new
    google.maps.LatLng(-12.072547590253286, -77.06911259765627));

    //*************************************************************************************************************************


}

function calcularDistanciaEntre(iniPos, endPos) {

    var dmreq = {
    avoidHighways:false,
    avoidTolls:false,
    destination:endPos,
    origin:iniPos,
    travelMode:google.maps.TravelMode.DRIVING,
    unitSystem:google.maps.UnitSystem.METRIC
    };

    var dms = new google.maps.DirectionsService();

    dms.route(dmreq, function(dmres, dmst) {
    if (dmst == google.maps.DirectionsStatus.OK) {
    console.log("distance=" + dmres.routes[0].legs[0].distance.value + "m.");
    // alert("distance=" + dmres.routes[0].legs[0].distance.value + "m.");
    var dirRender = new google.maps.DirectionsRenderer({
    map:map,
    directions:dmres
    });
    }
    });


}

function marcarPunto(location, nombre) {
    var marker = new google.maps.Marker({
    position: location,
    map: map
    });

    colocarNombre(marker, nombre);
}

function colocarNombre(marker, nombre) {
    var infowindow = new google.maps.InfoWindow(
    { content: nombre,
    size: new google.maps.Size(50, 50)
    });
    google.maps.event.addListener(marker, 'click', function() {
    infowindow.open(map, marker);
    });
}

function initializeMap(){
     var latlng = new google.maps.LatLng(-12.07, -77.09);
     var myOptions = {
     zoom: 15,
     center: latlng,
     mapTypeId: google.maps.MapTypeId.ROADMAP
     };
   latitud = null;
   longitud = null;
   var map = new google.maps.Map(document.getElementById("map_canvas"),myOptions);
    google.maps.event.addListener(map, 'click', function(event) {
        map = null;
        map = new google.maps.Map(document.getElementById("map_canvas"),myOptions);
        var location = event.latLng;
        latitud = location.lat();
        longitud = location.lng();
        placeMarker(event.latLng,map);
  });
}

function placeMarker(location,map) {
  var marker = new google.maps.Marker({
      position: location,
      draggable : true,
      map: map
  });

  map.setCenter(location);

}

function initializeMapCalcularRuta(){
     var latlng = new google.maps.LatLng(-12.07, -77.09);
     var myOptions = {
     zoom: 15,
     center: latlng,
     mapTypeId: google.maps.MapTypeId.ROADMAP
     };

   var map = new google.maps.Map(document.getElementById("map_canvas"),myOptions);
 }



